package com.alameda.facade.media;

import com.alameda.danmaku.api.ApVideoDanmakuProvider;
import com.alameda.history.api.ApVideoHistoryProvider;
import com.alameda.history.dto.ApVideoHistoryDTO;
import com.alameda.media.dto.AdMediaDTO;
import com.alameda.statement.api.AdSystemRecordProvider;
import com.alameda.statement.enums.AdSystemRecordEnum;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 媒体文件 接入层
 *
 * @author Lv
 * @date 2024/07/20
 */
@Component
public class AdMediaFacade {

    @DubboReference
    private ApVideoHistoryProvider apVideoHistoryProvider;

    /**
     * 删除播放记录
     *
     * @param idList 媒体文件id集合
     * @return
     */
    public Boolean removeHistoryByMediaIdList(List<Long> idList) {
        return apVideoHistoryProvider.removeByMediaIdList(idList);
    }

    /**
     * 修改播放记录信息
     *
     * @param adMediaDTO 媒体文件信息
     * @return
     */
    public Boolean updateMediaHistory(AdMediaDTO adMediaDTO) {
        ApVideoHistoryDTO apVideoHistoryDTO = ApVideoHistoryDTO.builder()
                .videoId(adMediaDTO.getId())
                .videoName(adMediaDTO.getFileName())
                .videoCover(adMediaDTO.getFileCover())
                .build();

        return apVideoHistoryProvider.updateMediaHistory(apVideoHistoryDTO);
    }

    @DubboReference
    private AdSystemRecordProvider adSystemRecordProvider;

    /**
     * 存储系统业务量记录
     *
     * @param adSystemRecordEnum 系统记录类型
     * @return
     */
    @Async
    public void saveRecord(AdSystemRecordEnum adSystemRecordEnum) {
        adSystemRecordProvider.saveRecord(adSystemRecordEnum);
    }

    @DubboReference
    private ApVideoDanmakuProvider apVideoDanmakuProvider;

    /**
     * 删除视频弹幕
     *
     * @param idList 媒体文件id集合
     * @return
     */
    public Boolean removeDanmakuByMediaIdList(List<Long> idList) {
        return apVideoDanmakuProvider.removeDanmakuByMediaIdList(idList);
    }
}
